home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWHashTable.z / RWHashTable
Encoding:
Text File  |  2002-10-03  |  13.4 KB  |  331 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                            RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWHashTable - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/hashtab.h>
  13.  
  14.  
  15.  
  16.               RWHashTable h ;
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      This class is a simple hash table for objects inheriting from
  23.      RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee.  It uses chaining (as implemented by class
  24.      RRRRWWWWSSSSlllliiiissssttttCCCCoooolllllllleeeeccccttttaaaabbbblllleeeessss) to resolve hash collisions.  Duplicate objects are
  25.      allowed.  An object stored by RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee must inherit from the abstract
  26.      base class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee, with suitable definition for virtual functions
  27.      hhhhaaaasssshhhh(((()))) and iiiissssEEEEqqqquuuuaaaallll(((()))) (see class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee). To find an object that
  28.      matches a key, the key's virtual function hhhhaaaasssshhhh(((()))) is first called to
  29.      determine in which bucket the object occurs. The bucket is then searched
  30.      linearly by calling the virtual function iiiissssEEEEqqqquuuuaaaallll(((()))) for each candidate,
  31.      with the key as the argument.  The first object to return TTTTRRRRUUUUEEEE is the
  32.      returned object.  The initial number of buckets in the table is set by
  33.      the constructor.  There is a default value.  If the number of items in
  34.      the collection greatly exceeds the number of buckets then efficiency will
  35.      sag because each bucket must be searched linearly.  The number of buckets
  36.      can be changed by calling member function rrrreeeessssiiiizzzzeeee(((())))....  This will require
  37.      that all objects be rehashed.  The iterator for this class is
  38.      RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeeeIIIItttteeeerrrraaaattttoooorrrr.
  39.  
  40. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  41.      None
  42.  
  43. EEEExxxxaaaammmmpppplllleeee
  44.               #include <rw/hashtab.h>
  45.           #include <rw/colldate.h>
  46.           #include <rw/rstream.h>
  47.           main(){
  48.            RWHashTable table;
  49.            RWCollectableDate *july
  50.                 = new RWCollectableDate(7, "July", 1990);
  51.            RWCollectableDate *may
  52.                 = new RWCollectableDate (1, "May", 1977);
  53.            RWCollectableDate *feb
  54.                 = new RWCollectableDate (22, "Feb", 1983);
  55.            RWCollectableDate *aug
  56.                 = new RWCollectableDate (2, "Aug", 1966);
  57.            table.insert(july);
  58.            table.insert(may);
  59.            table.insert(feb);
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                            RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.            table.insert(aug);
  75.            cout << "Table contains " << table.entries() << " entries.0;
  76.            RWCollectableDate key(22, "Feb", 1983);
  77.            cout << "It does ";
  78.            if (!table.contains(&key)) cout << "not ";
  79.            cout << "contain the key " << key << endl;
  80.  
  81.            delete july;
  82.            delete may;
  83.            delete feb;
  84.            delete aug;
  85.            return 0;
  86.           }
  87.  
  88.  
  89.      PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt::::
  90.  
  91.               Table contains 4 entries.
  92.  
  93. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  94.      It does contain the key February 22, 1983
  95.  
  96.  
  97.  
  98.               RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee(size_t N = RWCollection::DEFAULT_CAPACITY);
  99.  
  100.  
  101.      Construct an empty hash table with NNNN buckets.
  102.  
  103.               RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee(const RWHashTable& t);
  104.  
  105.  
  106.      Copy constructor.  Create a new hash table as a shallow copy of the table
  107.      tttt.  The new table will have the same number of buckets as the old table.
  108.      Hence, the members need not be and will not be rehashed.
  109.  
  110. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss
  111.               void
  112.           ooooppppeeeerrrraaaattttoooorrrr====(const RWHashTable& t);
  113.  
  114.  
  115.      Assignment operator.  Sets self as a shallow copy of tttt.  Afterwards, the
  116.      two tables will have the same number of buckets.  Hence, the members need
  117.      not be and will not be rehashed.
  118.  
  119.               RWBoolean
  120.           ooooppppeeeerrrraaaattttoooorrrr========(const RWHashTable& t) const;
  121.  
  122.  
  123.      Returns TTTTRRRRUUUUEEEE if self and tttt have the same number of elements and if for
  124.      every key in self there is a corresponding key in tttt which iiiissssEEEEqqqquuuuaaaallll.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                            RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               RWBoolean
  141.           ooooppppeeeerrrraaaattttoooorrrr<<<<====(const RWHashTable& t) const;
  142.  
  143.  
  144.      Returns TTTTRRRRUUUUEEEE  if self is a subset of tttt, that is, every element of self
  145.      has a counterpart in tttt which iiiissssEEEEqqqquuuuaaaallll.  NNNNooootttteeee:  If you inherit from
  146.      RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee in the presence of the Standard C++ Library, we recommend
  147.      that you override this operator and explicitly forward the call.
  148.      Overload resolution in C++ will choose the Standard Library provided
  149.      global operators over inherited class members.  These global definitions
  150.      are not appropriate for set-like partial orderings.
  151.  
  152.               RWBoolean
  153.           ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWHashTable&) const;
  154.  
  155.  
  156.      Returns the negation of ooooppppeeeerrrraaaattttoooorrrr========(((()))), above.
  157.  
  158. MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  159.               virtual void
  160.           aaaappppppppllllyyyy(RWapplyCollectable ap, void*);
  161.  
  162.  
  163.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.  The function pointed to by aaaapppp will be
  164.      called for each member in the collection.  Because of the nature of
  165.      hashing collections, this will not be done in any particular order.  The
  166.      function should not do anything that could change the hash value or
  167.      equality properties of the objects.
  168.  
  169.               virtual RWspace
  170.           bbbbiiiinnnnaaaarrrryyyySSSSttttoooorrrreeeeSSSSiiiizzzzeeee() const;
  171.  
  172.  
  173.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  174.  
  175.               virtual void
  176.           cccclllleeeeaaaarrrr();
  177.  
  178.  
  179.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  180.  
  181.               virtual void
  182.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  183.  
  184.  
  185.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  186.  
  187.               virtual int
  188.           ccccoooommmmppppaaaarrrreeeeTTTToooo(const RWCollectable*) const;
  189.  
  190.  
  191.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                            RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               virtual RWBoolean
  207.           ccccoooonnnnttttaaaaiiiinnnnssss(const RWCollectable*) const;
  208.  
  209.  
  210.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  211.  
  212.               virtual size_t
  213.           eeeennnnttttrrrriiiieeeessss() const;
  214.  
  215.  
  216.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  217.  
  218.               virtual RWCollectable*
  219.           ffffiiiinnnndddd(const RWCollectable*) const;
  220.  
  221.  
  222.      Redefined  from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  223.  
  224.               virtual unsigned
  225.           hhhhaaaasssshhhh() const;
  226.  
  227.  
  228.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  229.  
  230.               virtual RWCollectable*
  231.           iiiinnnnsssseeeerrrrtttt(RWCollectable* a);
  232.  
  233.  
  234.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.  Returns aaaa if successful, nnnniiiillll otherwise.
  235.  
  236.               virtual RWClassID
  237.           iiiissssAAAA() const;
  238.  
  239.  
  240.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn to return ________RRRRWWWWHHHHAAAASSSSHHHHTTTTAAAABBBBLLLLEEEE.
  241.  
  242.               virtual RWBoolean
  243.           iiiissssEEEEmmmmppppttttyyyy() const;
  244.  
  245.  
  246.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  247.  
  248.               virtual RWBoolean
  249.           iiiissssEEEEqqqquuuuaaaallll(const RWCollectable*) const;
  250.  
  251.  
  252.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  253.  
  254.               virtual RWCollectable*
  255.           nnnneeeewwwwSSSSppppeeeecccciiiieeeessss() const;
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                            RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  273.  
  274.               virtual size_t
  275.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const RWCollectable*) const;
  276.  
  277.  
  278.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  279.  
  280.               virtual RWCollectable*
  281.           rrrreeeemmmmoooovvvveeee(const RWCollectable*);
  282.  
  283.  
  284.      Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  285.  
  286.               virtual void
  287.           rrrreeeemmmmoooovvvveeeeAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(const RWCollectable*);
  288.  
  289.  
  290.      Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  291.  
  292.               virtual void
  293.           rrrreeeessssiiiizzzzeeee(size_t n = 0);
  294.  
  295.  
  296.      Resizes the internal hash table to have nnnn buckets.  This causes rehashing
  297.      all the members of the collection.  If nnnn is zero, then an appropriate
  298.      size will be picked automatically.
  299.  
  300.               virtual void
  301.           rrrreeeessssttttoooorrrreeeeGGGGuuuuttttssss(RWvistream&);
  302.           virtual void
  303.           rrrreeeessssttttoooorrrreeeeGGGGuuuuttttssss(RWFile&);
  304.           virtual void
  305.           ssssaaaavvvveeeeGGGGuuuuttttssss(RWvostream&) const;
  306.           virtual void
  307.           ssssaaaavvvveeeeGGGGuuuuttttssss(RWFile&) const;
  308.  
  309.  
  310.      Inherited from class RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn.
  311.  
  312.               RWStringID
  313.           ssssttttrrrriiiinnnnggggIIIIDDDD();
  314.  
  315.  
  316.      (acts virtual) Inherited from class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee.
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.